<template>
  <div>

    <el-form ref="editForm" :model="formFileds">
      <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item>
            <el-input v-model="formFileds.text"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item>
            <el-button type="primary" @click="search()">查询
            </el-button>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item>
            <el-button type="primary" @click="open()">增加
            </el-button>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>

    <!--表格内容-->
    <el-table ref="list" :data="tableData" style="width: 100%; margin-bottom: 5px;" border stripe highlight-current-row
      :header-cell-style="{textAlign:'center'}" :cell-style="{textAlign:'center'}">
      <el-table-column property="wthtbh" label="委托合同编号" width="130px">
      </el-table-column>
      <el-table-column property="wtr" label="委托人">
      </el-table-column>
      <el-table-column property="pmr" label="拍卖人">
      </el-table-column>
      <el-table-column property="bdzmc" label="标的总名称" width="100px">
      </el-table-column>
      <el-table-column property="pmfs" label="拍卖方式">
      </el-table-column>
      <el-table-column property="pmksrq" label="拍卖开始日期" width="250px">
      </el-table-column>
      <el-table-column property="pmdd" label="拍卖地点">
      </el-table-column>
      <el-table-column property="ggksrq" label="公告开始时间" width="200px">
      </el-table-column>
      <el-table-column property="ggjsrq" label="公告结束时间" width="200px">
      </el-table-column>
      <el-table-column property="sfkygg" label="是否可以公告" width="150px">
      </el-table-column>
      <el-table-column property="zdjmrs" label="最低竞买人数" width="150px">
      </el-table-column>
      <el-table-column property="jkzffs" label="支付方式">
      </el-table-column>
      <el-table-column property="htksrq" label="合同开始日期" width="200px">
      </el-table-column>
      <el-table-column property="htjsrq" label="合同结束日期" width="200px">
      </el-table-column>
      <el-table-column property="ggmtmc" label="公告媒体名称" width="150px">
      </el-table-column>

      <el-table-column label="操作" fixed="right" width="150px">
        <template slot-scope="scope">
          <el-dropdown @command="handleCommand" v-if="scope.row.fbzt == '待提交'">
            <el-button type="primary">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :command="beforeHandleCommand('goUrl',scope.row)">预览</el-dropdown-item>
              <el-dropdown-item :command="beforeHandleCommand('edit',scope.row)">编辑</el-dropdown-item>
              <el-dropdown-item :command="beforeHandleCommand('auto',scope.row)">自动生成</el-dropdown-item>
              <el-dropdown-item :command="beforeHandleCommand('noAuto',scope.row)">手写生成</el-dropdown-item>
              <el-dropdown-item :command="beforeHandleCommand('rowDel',scope.row)">删除</el-dropdown-item>
              <el-dropdown-item :command="beforeHandleCommand('up',scope.row)">上架</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

          <!-- <el-dropdown v-else>
            <el-button type="primary" @click="restart(scope.row)">
              上架
            </el-button>
          </el-dropdown> -->
          <el-button v-else type="danger" @click="down(scope.row)">下架</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--分页-->
    <el-pagination :page-sizes="[10, 20, 30, 40, 100]" :page-size=this.pageSize :total=this.total :current-page="currentPage" 
    layout="total, sizes, prev, pager, next, jumper" @current-change="getCurrentPage" @size-change="getSize">
    </el-pagination>

    <!-- 增加-弹出层 -->
    <ContractAdd ref="contractAddRef" v-if="contractAdd" :contractAdd="contractAdd" @dialogClose="dialogClose">
    </ContractAdd>
    <ContractEdit v-if="contractEdit" :contractEdit="contractEdit" @dialogClose="dialogClose" :rowData="rowData">
    </ContractEdit>
    <!-- 合同自动生成-弹出层 -->
    <ContractAuto ref="autoRef" v-if="autoEdit" :autoEdit="autoEdit" @dialogClose="dialogClose" :rowData="rowData">
    </ContractAuto>

  </div>
</template>

<script>
import ContractAuto from './contractAuto.vue';
import ContractAdd from './contractAdd.vue';
import ContractEdit from './editContract.vue';
import { getAll,getBy,createPDF,delData,editData,submit,shelves } from '@/api/auctionManage/entrustmentContract';

export default {
  name: "entrustmentContract",
  components: {
    ContractAuto,
    ContractAdd,
    ContractEdit
  },
  data () {
    return {
      pageSize: 10,
      total: 0,
      currentPage: 1,
      param: '',
      formFileds: {
        text: '',
        param: ''
      },
      tableData: [
        {
          wthtbh: "",//委托合同编号
          wthtmc: '',//委托合同名称
          wtr: "",//委托人
          wtdlr: "",//委托代理人
          pmr: "",//拍卖人
          pmdlr: "",//拍卖代理人
          bdzmc: "",//标的总名称
          zblj: 0,//总保留价
          zqpj: 0,//总起拍价
          zecblj: 0,//总二次保留价
          zjdbfb: 0,//总降低百分比
          pmfs: "",//拍卖方式
          wtpgr: "",//委托评估人
          pgfycdr: "",//评估费用承担人
          jdr: "",//鉴定人
          jdfycdr: "",//鉴定费用承担人
          pmksrq: "",//拍卖开始日期
          pmdd: "",//拍卖地点
          ggksrq: "",//公告开始时间
          ggjsrq: "",//公告结束时间
          ggmtmc: "",//公告媒体名称
          sfkygg: 'true',//保留价与保证金是否可以公告
          bzj: 0,//保证金
          bzjzbljbfb: 0,//保证金所占保留价百分比
          jmrsxz: '',//竞买人数选择
          zdjmrs: 0,//最低竞买人数
          sflhpm: 'true',//是否同意联合拍卖
          jfr: "",//交付人
          jfjzrq: "",//交付截止日期
          jfdd: "",//交付地点
          jffs: "",//交付方式
          bgfcdr: "",//保管费承担人
          yjzcjjbfb: 0,//佣金占成交价百分比
          hlfybk: "",//合理费用包括
          hlfyje: 0,//合理费用金额
          hlfxzts: 0,//合理费限制天数
          jkzffs: "",//价款支付方式
          jkzfqx: "",//价款支付期限
          pmccyy: "",//拍卖撤除原因
          wscxz: "",//标的未售出后选择
          xdlhts: 0,//限定领回天数
          wlhclfs: "",//未领回处理方式
          bmnr: "",//保密内容
          wyj: 0,//违约金
          wyjzbljbfb: 0,//违约金占保留价百分比
          wyzr: "",//违约责任
          zyjjxz: "1",//争议解决选择
          zcwyhmc: "",//仲裁委员会名称
          rmfymc: "",//人民法院名称
          ydy: "",//约定一
          yde: "",//约定二
          yds: "",//约定三
          htksrq: "",//合同开始时间
          htjsrq: "",//合同结束时间
          wtrqz: "",//委托人签字
          wtrkhh: "",//委托人开户行
          wtrzh: "",//委托人账号
          wtrdh: "",//委托人电话
          wtrqzrq: "",//委托人签字日期
          pmrqz: '',//拍卖人签字
          pmrkhh: "",//拍卖人开户行
          pmrzh: "",//拍卖人账号
          pmrdh: "",//拍卖人电话
          pmrqzrq: "",//拍卖人签字日期
          pmdw: "",//拍卖单位
          pmje: 0,//拍卖金额
          remark: "",
          deleteflag: false,
        },
      ],
      autoEdit: false,
      contractAdd: false,
      contractEdit: false,
      rowData: {},
    }
  },
  methods: {
    goUrl (url) {
      this.$message.warning('该功能正在开发');
      return ;
      window.open(url, "_blank");
    },
    noAuto () {
      // this.$message.warning('该功能正在开发');
      // return ;
      window.open('/api/download/pdf/wthtmb.pdf', "_blank")
    },

    handleRowClick (row, event, column) {

      // 仅选中当前行
      this.setCurRowChecked(row);
    },
    handleCheckedAllAndCheckedNone (selection) {

      // 当前选中仅一行时操作-（当前表格行高亮）
      1 != selection.length && this.$refs.list.setCurrentRow();
    },
    dialogClose () {
      this.autoEdit = false;
      this.contractAdd = false;
      this.contractEdit = false;
      this.getList();
    },
    auto (row) {
      console.log(row);
      createPDF(row.wthtbh).then((res) => {
        if(res){
          window.open(res.data);
        }
      })
      // this.rowData = row;
      // this.autoEdit = true;
      // window.open(url, "_blank");
    },
    rowDel (row) {
      // 让当前删除按钮失焦
      // event.target.blur();

      this.$confirm('确定要删除当前行吗？', '删除', {
        comfirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {
        delData(row.id).then((res) => {
          if(res){
            this.tableData.splice(row.id, 1);
            this.$message.success('删除成功');
            this.getList();
          }
        })
      });
    },

    //打开新增合同窗口
    open () {
      this.contractAdd = true;
    },
    edit(row){
      this.rowData = row;
      this.contractEdit = true;
    },
    formatData(tableData){
      for(let item in tableData){
        if(this.tableData[item].sfkygg == true){
          this.tableData[item].sfkygg = '是';
        }
        else{
          this.tableData[item].sfkygg = '否';
        }
      }
      return tableData;
    },
    getCurrentPage(currentPage){
      console.log(currentPage);
      this.currentPage = currentPage;
      this.getList();
    },
    getSize(pageSize){
      console.log(pageSize);
      this.pageSize = pageSize;
      this.getList();
    },
    getList() {
      this.param = 'pageno=' + this.currentPage + '&countonepage=' + this.pageSize;
      getAll(this.param).then((res) => {
        if(res){
          console.log(res.data.list);
          this.total = res.data.total;
          this.tableData = res.data.list;
          this.tableData = this.formatData(this.tableData);
        }
      })
    },
    search(){
      this.formFileds.param = 'input=' + this.formFileds.text + '&pageno='+this.currentPage + '&countonepage=' + this.pageSize;
      getBy(this.formFileds.param).then((res) => {
        console.log(res);
        this.total = res.data.total;
        this.tableData = res.data.list;
        this.tableData = this.formatData(this.tableData);
      })
    },
    handleCommand(command){
      if(command.command == 'goUrl'){
        this.goUrl();
      }
      else if(command.command == 'edit'){
        this.edit(command.row);
      }
      else if(command.command == 'auto'){
        this.auto(command.row);
      }
      else if(command.command == 'noAuto'){
        this.noAuto();
      }
      else if(command.command == 'rowDel'){
        this.rowDel(command.row);
      }
      else if(command.command == 'up'){
        this.up(command.row);
      }
    },
    beforeHandleCommand(command,row){
      return{
        'command': command,
        'row': row
      }
    },
    // restart(row){
    //   row.deleteflag = false;
    //   row.zblj = parseInt(row.zblj);
    //   row.zqpj = parseInt(row.zqpj);
    //   row.zecblj = parseInt(row.zecblj);
    //   row.bzj = parseInt(row.bzj);
    //   row.wyj = parseInt(row.wyj);
    //   row.pmje = parseInt(row.pmje);
    //   row.hlfyje = parseInt(row.hlfyje);
    //   row.zdjmrs = parseInt(row.zdjmrs);
    //   row.xdlhts = parseInt(row.xdlhts);
    //   row.hlfxzts = parseInt(row.hlfxzts);
    //   row.zjdbfb = parseFloat(row.zjdbfb);
    //   row.bzjzbljbfb = parseFloat(row.bzjzbljbfb);
    //   row.wyjzbljbfb = parseFloat(row.wyjzbljbfb);
    //   row.yjzcjjbfb = parseFloat(row.yjzcjjbfb);
    //   if(row.sfkygg == 'true'){
    //       row.sfkygg = true;
    //   }
    //   else{
    //       row.sfkygg = false;
    //   }
    //   if(row.sflhpm == 'true'){
    //       row.sflhpm = true;
    //   }
    //   else{
    //       row.sflhpm = false;
    //   }
    //   if(row.jmrsxz == 'true'){
    //       row.jmrsxz = true;
    //   }
    //   else{
    //       row.jmrsxz = false;
    //   }
    //   editData(row).then((res) => {
    //       if(res){
    //           console.log(res);
    //           this.$message.success('上架成功');
    //           // this.getList();
    //       }
    //   });
    // },
    up(row){
      let data = 'id=' + row.id;
      submit(data).then((res) => {
        if(res){
          console.log(res);
          this.$message.success('上架成功');
          this.getList();
        }
      })
    },
    down(row){
      let data = 'id=' + row.id;
      shelves(data).then((res) => {
        if(res){
          console.log(res);
          this.$message.success('下架成功');
          this.getList();
        }
      })
    }
  },
  mounted(){
    this.getList();
  }
}
</script>
      
<style scoped lang="less">
.el-form {
  padding: 0 10px;
}

.el-date-editor {
  width: 100% !important;
}

</style>
      